<template>
  <div>
    <!-- 面包屑 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>商品管理</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- header -->
    <div style="margin-top: 15px">
      <el-input
        placeholder="请输入内容"
        v-model="searchVal"
        class="input-with-select"
      >
        <el-button
          slot="append"
          icon="el-icon-search"
          @click="search"
        ></el-button>
      </el-input>
      <el-button type="primary" @click="addopen">添加商品</el-button>
    </div>

    <!-- 添加弹出框 -->
    <el-dialog :title="title" :visible.sync="dialogVisible" width="50%">
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>

    <!-- 表格渲染 -->
    <el-table
      ref="singleTable"
      :data="tableData"
      highlight-current-row
      style="width: 100%"
    >
      <el-table-column type="index" width="50"> </el-table-column>
      <el-table-column property="goods_name" label="商品名称"> </el-table-column>
      <el-table-column property="goods_price" label="商品价格（元）">
      </el-table-column>
      <el-table-column property="goods_weight" label="商品重量">
      </el-table-column>
      <el-table-column property="add_time" label="创建时间"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row.id)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getgoods } from "../utils/api";
export default {
  props: {},
  data() {
    return {
      searchVal: "",
      dialogVisible: false,
      title: "",
      tableData: [],
      pages: {
        pagenum: 1,
        pagesize: 10,
        query: "",
      },
    };
  },
  computed: {},
  created() {
    // this.render();
  },
  mounted() {},
  watch: {},
  methods: {
    // render() {
    //   getshop({ pagesize: this.pagesize, pagenum: this.pagenum }).then(
    //     (res) => {
    //       console.log(res);
    //     }
    //   );
    // },
    addopen() {
      this.title = "添加";
      this.$router.push('/goods2')

    },
    // 搜索
    search() {},
    // 编辑
    handleEdit(row) {},
    // 删除
    handleDelete(id) {},
  },
  components: {},
  created() {
    getgoods(this.pages).then((res) => {
      console.log(res);
      this.tableData = res.data.goods;
    });
  },
};
</script>

<style scoped lang="scss">
.el-input {
  width: 500px;
}
</style>
